package com.he.yiliao.DAo;
import com.he.yiliao.bean.wenxian;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
public class UserDao {
    public List<wenxian> selectAll ()
    {
        List<wenxian> list=new ArrayList<>();
        Connection conn = DBOpenHelper.getConn();
        Statement state = null;
        ResultSet rs = null;
        wenxian wenxian=null;
        String sql="select * from wenxian";
        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            while (rs.next()) {
                String wen = rs.getString("wen");
                String di = rs.getString("di");

                wenxian=new wenxian(wen,di);
                list.add(wenxian);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBOpenHelper.close(rs, state, conn);
        }
        return list;
    }
    public List<wenxian> by (String name)
    {
        List<wenxian> list=new ArrayList<>();
        Connection conn = DBOpenHelper.getConn();
        Statement state = null;
        ResultSet rs = null;
        wenxian wenxian=null;
        String sql="select * from wenxian where di like '%"+name+"%'";
        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);
            while (rs.next()) {
                String wen = rs.getString("wen");
                String di = rs.getString("di");

                wenxian=new wenxian(wen,di);
                list.add(wenxian);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBOpenHelper.close(rs, state, conn);
        }
        return list;
    }
}
